package club.cearnach.web.controller.movie;

import club.cearnach.entity.Person;
import club.cearnach.api.form.PageBean;
import club.cearnach.api.service.IPersonService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 阮胜
 * @date 2018/5/22 8:22
 */
@Controller
@Slf4j
@RequestMapping("/person")
@Api(tags = "人物控制层")
public class PersonController {
    private final IPersonService personService;

    public PersonController(IPersonService personService) {
        this.personService = personService;
    }

    @GetMapping("/list/grid")
    public String listGrid( Model model) {
        model.addAttribute("personCount", personService.count());
        return "movie/person-list-grid";
    }

    @GetMapping("/list/grid/fragment")
    public String listGridFragment(PageBean pageBean, Model model) {
        Page<Person> personPage = personService.findAllOrderByCreateDate(pageBean);
        model.addAttribute(personPage.getContent());
        model.addAttribute("totalPage", personPage.getTotalPages());
        model.addAttribute("currentPage", pageBean.getPage());
        return "movie/person-list-grid-fragment";
    }

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Integer id) {
        return "movie/person-detail";
    }
}